/**
 * 
 */
package com.kingcore.pda.core.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Util for web page.
 * @author Zeven
 *
 */
public class WebUtil {
 
	public static List<String> getFolderList(String filePath,String prefix, String suffix){
		//"D:\tomcat-4.1.30\webapps\watermis\abc"
		java.io.File t_file = new java.io.File(filePath);
	    if(!t_file.exists()){
	    	return Collections.emptyList();
	    	
	    } else {
	    	List<String> retList = new ArrayList<String>();
			java.util.List<java.io.File> files = java.util.Arrays.asList(t_file.listFiles());
			java.util.Collections.sort(files, new java.util.Comparator<java.io.File>(){
				public int compare(java.io.File o1, java.io.File o2) {
				if(o1.isDirectory() && o2.isFile())
					return -1;
				if(o1.isFile() && o2.isDirectory())
						return 1;
				return o1.getName().compareTo(o2.getName());
				}
			});
			String fileName = null;
			for (java.io.File file : files) {
				if(file.isDirectory()){
					fileName = file.getName();
					if (prefix!=null && fileName.startsWith(prefix)==false) {
						continue;
					}
					if (suffix!=null && fileName.endsWith(suffix)==false) {
						continue;
					}
					retList.add(fileName);
				}
			}
			return retList;
	    }
	}
	 
}
